#include "boosters.h"

void Boosters::draw() {
	float direction = -cpvtoangle(dir_) * rToDeg;

	glTranslatef(pos_.x, pos_.y, 0.0);
	glRotatef(direction, 0.0, 0.0, 1.0);

	if(on) {
		glBegin(GL_POLYGON); {
			glColor4f(aR, aG, aB, aA);
			glVertex2f(vertii_[0].x, vertii_[0].y);
			glColor4f(bR, bG, bB, bA);
			glVertex2f(vertii_[1].x, vertii_[1].y);
			glColor4f(cR, cG, cB, cA);
			glVertex2f(vertii_[2].x, vertii_[2].y);
			glColor4f(bR, bG, bB, bA);
			glVertex2f(vertii_[3].x, vertii_[3].y);
			glColor4f(aR, aG, aB, aA);
			glVertex2f(vertii_[4].x, vertii_[4].y);
		} 
		glEnd();
	}

	glBegin(GL_POLYGON); {
		glColor4f(pR, pG, pB, pA);
		glVertex2f(portVertii_[0].x, portVertii_[0].y);
		glVertex2f(portVertii_[1].x, portVertii_[1].y);
		glVertex2f(portVertii_[2].x, portVertii_[2].y);
		glVertex2f(portVertii_[3].x, portVertii_[3].y);
	}
	glEnd();
	
	glRotatef(-direction, 0.0, 0.0, 1.0);
	glTranslatef(-pos_.x, -pos_.y, 0.0);
}
    
void Boosters::update(float step) {
	if(on) {
		cpVect direction = cpvforangle(getHost()->a);
		cpBodyApplyImpulse(getHost(), cpvrotate(force_, direction), cpvrotate(pos_, direction));
	}
}
